package servlet;

import com.alibaba.fastjson.JSON;
import domain.Province;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class ReadyAjaxServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        response.setHeader("Access-Control-Allow-Origin","*");
        /*ArrayList arrayList=new ArrayList();
        arrayList.add("洗衣液");
        arrayList.add("沐浴露");
        arrayList.add("卫生巾");
        Province province=new Province("生活用品",arrayList);*/
//        String provinceText= JSON.toJSONString(province);
        List<Province> list = new ArrayList<>();
        ArrayList arrayList1=new ArrayList();
        arrayList1.add("洗衣液");
        arrayList1.add("沐浴露");
        arrayList1.add("卫生巾");
        list.add(new Province("生活用品",arrayList1));

        ArrayList arrayList2=new ArrayList();
        arrayList2.add("手机");
        arrayList2.add("平板");
        arrayList2.add("电脑");
        list.add(new Province("数码产品",arrayList2));

        ArrayList arrayList3=new ArrayList();
        arrayList3.add("面包");
        arrayList3.add("泡面");
        arrayList3.add("熟食");
        list.add(new Province("美食",arrayList3));
        String listText= JSON.toJSONString(list);
        response.getWriter().write(listText);
//        response.getWriter().write(provinceText);
    }
}
